package cn.jsp.jdbc;

import lombok.SneakyThrows;

import java.lang.reflect.Field;
import java.sql.ResultSet;


public class GeneralRowProcessor<T> implements RowProcessor<T> {
    Class<T> target;
    public GeneralRowProcessor(Class<T> target){
        this.target=target;
    }
    @SneakyThrows
    @Override
    public T process(ResultSet rs) {
        //new
        T obj=target.getDeclaredConstructor().newInstance();
        //set
        for(Field field:target.getDeclaredFields()){
            field.setAccessible(true);
            field.set(obj,rs.getObject(field.getName()));
        }

        return obj;
    }
}
